package com.shihb.structuralpatterns;/**
 *Description:桥接模式
 * 适合多维度场景
 *Version:1.0.0
 *@author shihb
 *@date 2020/4/21 11:19
 */
public class BridgePattern {

  public static void main(String[] args) {
    // 组合将两个维度联系在一起
    Lenovo lenovo = new Lenovo();
    Apple apple = new Apple();
    ComputerType appleDesktop = new Desktop(apple);
    appleDesktop.info();
    ComputerType lenovoLaptop = new Laptop(lenovo);
    lenovoLaptop.info();
  }
}

/**
 * 品牌维度
 */
interface Brand {
  void info();
}

class Lenovo implements Brand {

  @Override
  public void info() {
    System.out.print("联想");
  }
}
class Apple implements Brand {

  @Override
  public void info() {
    System.out.print("苹果");
  }
}

/**
 * 电脑类型维度
 */
abstract class ComputerType {
  protected Brand brand;

  public ComputerType(Brand brand) {
    this.brand = brand;
  }
  public void info(){
    this.brand.info();
  }
}

class Desktop extends  ComputerType{

  public Desktop(Brand brand) {
    super(brand);
  }
  @Override
  public void info(){
    super.info();
    System.out.println("台式机");
  }
}
class Laptop extends  ComputerType{

  public Laptop(Brand brand) {
    super(brand);
  }
  @Override
  public void info(){
    super.info();
    System.out.println("笔记本电脑");
  }
}
